<template>
    <div class="school">    
        <h1>学校{{name}}{{address}}</h1>
    </div>
</template>

<script>
    import pubsub from 'pubsub-js'
    export default {
        name:"MySchool",
        data(){
            return {
                name:'zzz1',
                address:"zzzzzzzzfffffff",
            }
        },
        mounted() {
            // this.$bus.$on('schoolHello',()=>{
            //     console.log("schoolget")
            // })
            // 往pubsub里面订阅, 返回一个数字id
            this.pubsubId=pubsub.subscribe('hello',(msgName,data)=>{
                console.log('hello', msgName, data)
            })
            console.log(this.pubsubId, '')
        },
        beforeDestroy() {
            //在组件销毁前解绑自定义事件
            // this.$bus.$off('schoolHello')
            // 往pubsub里面取消订阅
            pubsub.unsubscribe(this.pubsubId)
        },
    }
</script>

<style scoped>
    .school{
        background-color: orange;
    }
</style>